package hust.cs.javacourse.search.index.impl;

import hust.cs.javacourse.search.index.AbstractTerm;
import hust.cs.javacourse.search.index.AbstractTermTuple;
/**
 * <pre>
 * AbstractTermTuple是所有TermTuple对象的抽象父类.
 *      一个TermTuple对象为三元组(单词，出现频率，出现的当前位置).
 *      当解析一个文档时，每解析到一个单词，应该产生一个三元组，其中freq始终为1(因为单词出现了一次).
 * </pre>
 *
 *
 */
public class TermTuple extends AbstractTermTuple {
    /**
     * 缺省构造函数
     */
    public TermTuple() {
        super();
    }

    /**
     * 带参构造函数
     * @param term
     * @param curPos
     */
    public TermTuple(AbstractTerm term, int curPos) {
        this.term = term;
        this.curPos = curPos;
    }

    /**
     * 返回Term
     * @return
     */
    public AbstractTerm getTerm() {
        return this.term;
    }
    /**
     * 返回TermTuple内容
     * @return
     */
    @Override
    public String toString() {


        String info = term.toString();
        //System.out.println("Info: " + info);
        info = info + "   curPos: " + this.curPos + "     fre: " + this.freq;
        //System.out.println("Info: " + info);
        return info;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof TermTuple) {
            AbstractTermTuple tp = (AbstractTermTuple) obj;
            return this.term.equals(tp.term) &&
                    this.curPos == tp.curPos &&
                    this.freq == tp.freq;
        }
        return false;
    }
}
